import * as THREE from 'three'

/**
 * 获取 Three.js 物体的中心点和尺寸大小
 * @param {THREE.Object3D} object - 需要计算的 Three.js 物体
 * @returns {{ center: THREE.Vector3, size: THREE.Vector3 }} - 物体的中心点 (世界坐标) 和 尺寸大小 (Vector3)
 */
export function getObjectBounds(object) {
  if (!object) {
    console.warn('getObjectBounds: 传入的 object 为空')
    return null
  }

  // 创建包围盒
  const box = new THREE.Box3().setFromObject(object)

  // 计算中心点
  const center = new THREE.Vector3()
  box.getCenter(center)

  // 计算尺寸大小
  const size = new THREE.Vector3()
  box.getSize(size)

  return { center, size }
}
